草庐IT

Module not found: Error: Package path 找不到模块

全部标签

ruby - 在 Ruby 模块上调用方法

我有以下Ruby代码:moduleMyModuleclassMyClassdefself.my_methodendendend要调用my_method,我输入MyModule::MyClass.my_method。我想在模块本身上为my_method编写一个包装器:MyModule.my_method这可能吗? 最佳答案 我不确定您想要实现什么,但是:如果您将其设为常规方法并使用module_function对其进行修改,您将能够以您选择的任何方式调用它。#!/usr/bin/ruby1.8moduleMyModuledefmy_m

ruby-on-rails - ERROR : While executing gem . .. (TypeError) 不兼容的编码文件格式(无法读取)

我在使用Ruby2.4.4版和macOSMojave运行bundleinstall时遇到了这个问题:Fetchingnokogiri1.8.5Installingnokogiri1.8.5withnativeextensionsGem::Ext::BuildError:ERROR:Failedtobuildgemnativeextension.ERROR:cannotdiscoverwherelibxml2islocatedonyoursystem.pleasemakesure`pkg-config`isinstalled.所以我跑了xcode-select--install但是当我运

【笔记】internal/modules/cjs/loader.js:985 throw err; ^ Error: Cannot find module ‘node:util‘

[root@localhostusr]#cnpm-vinternal/modules/cjs/loader.js:985throwerr;^Error:Cannotfindmodule‘node:util’Requirestack:/usr/local/node/lib/node_modules/cnpm/bin/cnpmatFunction.Module._resolveFilename(internal/modules/cjs/loader.js:982:15)atFunction.Module._load(internal/modules/cjs/loader.js:864:27)atM

ruby - 在另一个模块中扩展模块

我正在尝试定义几个模块,以便轻松地将一些实例和类方法添加到其他类中,这就是我正在做的事情:moduleFoomoduleBardefspeakputs"heythere"endendmoduleBazextendFoo::Bardefwelcomeputs"welcome,thisisaninstancemethod"endendendclassTalkerincludeFoo::BazendTalker.new.welcomeTalker.speak这个的输出是:welcome,thisisaninstancemethodundefinedmethod'speak'forTalker

javascript - Rails js.erb 文件找不到方法 "render"

我在JavascriptERB文件中有以下代码:$(document).ready(function(){$("#workout-week").append("show_training_period",:locals=>{:period=>@period})%>);});当我到达View时,出现以下错误:undefinedmethod`render'for#:0x00000005dbfe98>partial存在,局部变量非nil。知道为什么会发生这种情况吗?堆栈跟踪:app/assets/javascripts/slider.js.erb:2:in`evaluate_source't

ruby - 为 Ruby 编写模块

如何为ruby​​编写模块。在python中你可以使用#module.pydefhelloworld(name):print"Hello,%s"%name#main.pyimportmodulemodule.helloworld("Jim")回到问题,你如何在ruby​​中/为ruby​​创建一个模块 最佳答案 Ruby中的模块与Python中的模块有不同的用途。通常,您使用模块来定义可以包含在其他类定义中的通用方法。但是Ruby中的模块也可以像在Python中一样以类似的方式使用,只是将某些命名空间中的方法分组。因此,您在Ruby

Ruby 'is_a?' 需要类或模块 (TypeError)

我正在尝试使用Ruby并尝试创建一个小型银行账户程序。当我运行这行与create_account一起运行的特定代码时:unless@response.is_a?Integer&&@response.to_str.length==4puts"Yourresponsemustbe4numbersinlength."create_accountelse@pin=@responseputs"Yourpinhasbeenset."end我收到这样的回复:bank_account.rb:24:in'is_a?':classormodulerequired(TypeError)frombank_ac

ruby-on-rails - Ruby on Rails,找不到有效的 gem 'rails'

我安装了ruby​​并更新了ruby​​gems,现在我想下载rails3.2.13。我写geminstallrails-v3.2.13(我需要这个版本)我有这个错误ERROR:Couldnotfindavalidgem'rails'(=3.2.13),hereiswhy:Unabletodownloaddatafromhttps://rubygems.org/-SSL_connectSYSCALLreturned=5errno=0state=SSLv2/v3readserverhelloA(https://rubygems.org/specs.4.8.gz)ERROR:Possibl

ruby - Pry Error : Cannot find local context. 您是否使用了 `binding.pry`?

为什么我会收到此pry动错误?[36]pry(main)>s="pry"Error:Cannotfindlocalcontext.Didyouuse`binding.pry`?在此截屏视频中运行良好http://pryrepl.org/ 最佳答案 似乎s、c和n是pry-navgem上的保留命令,发现here,这可以帮助您逐步完成绑定(bind)。Pry.commands.alias_command'c','continue'Pry.commands.alias_command's','step'Pry.commands.alias

ruby - 如何在单独的类/模块/文件中编写 Thor 任务?

我在获取Thor时遇到了一些问题这样做,所以希望有人能指出我做错了什么。我有一个主类classMyApp我想为多个命名空间分成单独的文件,比如thorcreate:app_type和thorupdate:app_type.我找不到任何示例来说明应该如何将Thor应用程序分解成多个部分,而且我尝试过的方法似乎不起作用。举个例子,这个类我正试图从主Thor类中脱离出来:moduleThingsmoduleGroupingdesc"something","Dosomethingcoolinthisgroup"defsomething....endendend当我尝试在我的主类中包含或要求它时